
package org.finegold.core.context.config;

import org.finegold.core.context.FineContext;
import org.finegold.core.context.FineHttpHeadersGetter;
import org.finegold.core.context.FineServletContext;
import org.finegold.core.context.ServletHttpHeadersGetter;
import org.finegold.core.context.props.FineContextProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;

/**
 * fine 服务上下文配置
 *
 * @author QinXueFeng
 */
@Configuration(proxyBeanMethods = false)
@Order(Ordered.HIGHEST_PRECEDENCE)
@EnableConfigurationProperties(FineContextProperties.class)
public class FineContextAutoConfiguration {

	@Bean
	@ConditionalOnMissingBean
	public FineHttpHeadersGetter fineHttpHeadersGetter(FineContextProperties contextProperties) {
		return new ServletHttpHeadersGetter(contextProperties);
	}

	@Bean
	@ConditionalOnMissingBean
	public FineContext fineContext(FineContextProperties contextProperties, FineHttpHeadersGetter httpHeadersGetter) {
		return new FineServletContext(contextProperties, httpHeadersGetter);
	}

}
